package com.raven.craft.code.generator.mysql.mybatis;

import com.raven.craft.code.generator.common.util.StringUtil;
import com.raven.craft.code.generator.mysql.repo.entity.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Set;

/**
 * @author raven
 * @date 2019-04-04 17:42
 */
@Getter
@Setter
@ToString
public class EntityVo {

    public String targetPackage;
    private String name;
    private Set<String> imports;
    private Table table;

    public EntityVo(MyBatisProperties properties, Table table) {
        this.targetPackage = properties.getEntityPackage();
        this.name = StringUtil.trim(table.getName(), properties.getTrimPrefix(), properties.getTrimSuffix());
        this.imports = generateImportTypeSet(table);
        this.table = table;
    }

    private Set<String> generateImportTypeSet(Table table) {
        Set<String> set = table.getColumnJavaTypes();

        set.add("lombok.*");
        set.add("lombok.experimental.Accessors");
        set.add("com.baomidou.mybatisplus.annotation.*");
        set.add("com.baomidou.mybatisplus.extension.activerecord.Model");

        return set;
    }

}
